require( '$d/css/common.less' );
require( './style.less' );
define( [
  'require',
  'jquery',
  'header',
  'nav',
  './user_analyzing',
  './custom_menu',
  './auto_reply',
  'bigwe_utils',
  'plat_public',
  'selector'
], function( require, $ ) {
  var customMenu = require( './custom_menu' );
  var autoReply = require( './auto_reply' );
  var userAnalyzing = require( './user_analyzing' );

  var platPublic = require( 'plat_public' );

  var callbacks = [
    null,
    customMenu.tabChange,
    autoReply.tabChange
  ];

  var platformAndAccountInit = [
    customMenu.init,
    autoReply.init,
    userAnalyzing.init
  ];

  var platformAndAccountChange = [
    userAnalyzing.init,
    customMenu.customMenuObjChange,
    autoReply.autoReplyObjChange
  ]

  $( '#columns_nav' ).bwColumns( [ '用户管理', '自定义菜单', '自动回复' ], function( index ) {
    $.isFunction( callbacks[ index.index() ] ) && callbacks[ index.index() ].call( this );
  }, '#column_items' );

  $( document ).on( 'click', '.js_common_img_upload', function() {
    $( '#upload_img_btn' ).trigger( 'click' );
  } );

  platPublic.init( {
    callback: function( data ) {
      if ( !this.accountInit ) {
        this.accountInit = true;
        for ( var i in platformAndAccountInit ) {
          platformAndAccountInit[ i ] && platformAndAccountInit[ i ].apply( this, arguments );
        }
      } else {
        for ( var i in platformAndAccountChange ) {
          platformAndAccountChange[ i ].apply( this, arguments );
        }
      }
    }
  } );

} );
